package org.larkdoc.model.vo;

import java.util.List;
import java.util.Map;

import org.dozer.Mapping;
import org.larkdoc.util.DozerUtil;

/**
 * 分页数据，泛型<T>的数据不能直接获取，
 * 参照searchMapToTargetClass()使用。 
 * 
 * @author  zhangpeijun[zhangpeijun1024@qq.com]
 * @version  [v1.0.1, 2017年7月4日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class PageVO<T> extends RespBaseVO {
    
    /**
     * 注释内容
     */
    private static final long   serialVersionUID = 4916282748296022943L;
    
    /**
     * 每页条数
     */
    @Mapping("pageSize")
    private Integer             pageSize;
    
    /**
     * 当前页码
     */
    @Mapping("pageNum")
    private Integer             pageNum;
    
    /**
     * 总条数
     */
    @Mapping("total")
    private Integer             total;
    
    /**
     * 总页数
     */
    @Mapping("pages")
    private Integer             pages;
    
    /**
     * 开始行
     */
    @Mapping("startRow")
    private Integer             startRow;
    
    /**
     * 结束行
     */
    @Mapping("endRow")
    private Integer             endRow;
    
    /**
     * 排序
     */
    private String              orders;
    
    /**
     * 查询条件对象
     */
    private T                   search;
    
    /**
     * 查询条件对象
     */
    private Map<String, Object> searchMap;
    
    /**
     * 结果集
     */
    List<T>                     list;
    
    /**
     * 因form提交对象型json数据.
     * 泛型<T>不能直接表单赋值，只有通过searchMap转换。
     * 前端form提交的值因为：searchMap.property,searchMap[property] 
     * 
     * @param targetClass
     * @return [参数说明]
     * 
     * @return T [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     * @author tmmk
     * @version [v0.0.1, 2016年8月22日]
     */
    public <A> A searchMapToTargetClass(Class<A> targetClass) {
        return DozerUtil.conversion(this.searchMap, targetClass);
    }
    
    public Integer getPageSize() {
        return pageSize == null ? 10 : pageSize;
    }
    
    public void setPageSize(int pageSize) {
        this.pageSize = (pageSize < 0 ? 0 : pageSize);
    }
    
    public Integer getPageNum() {
        return pageNum == null ? 1 : pageNum;
    }
    
    public void setPageNum(int pageNum) {
        this.pageNum = (pageNum <= 0 ? 1 : pageNum);
    }
    
    public Integer getTotal() {
        return total;
    }
    
    public void setTotal(int total) {
        this.total = (total < 0 ? 0 : total);
    }
    
    public Integer getPages() {
        return pages;
    }
    
    public void setPages(int pages) {
        this.pages = (pages < 0 ? 0 : pages);
    }
    
    public Integer getStartRow() {
        return startRow;
    }
    
    public void setStartRow(int startRow) {
        this.startRow = (startRow < 0 ? 0 : startRow);
    }
    
    public Integer getEndRow() {
        return endRow;
    }
    
    public void setEndRow(int endRow) {
        this.endRow = (endRow < 0 ? 0 : endRow);
    }
    
    public String getOrders() {
        return orders;
    }
    
    public void setOrders(String orders) {
        this.orders = orders;
    }
    
    public List<T> getList() {
        return list;
    }
    
    public void setList(List<T> list) {
        this.list = list;
    }
    
    public T getSearch() {
        return search;
    }
    
    public void setSearch(T search) {
        this.search = search;
    }
    
    public Map<String, Object> getSearchMap() {
        return searchMap;
    }
    
    public void setSearchMap(Map<String, Object> searchMap) {
        this.searchMap = searchMap;
    }
    
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("PageVO [pageSize=");
        builder.append(pageSize);
        builder.append(", pageNum=");
        builder.append(pageNum);
        builder.append(", total=");
        builder.append(total);
        builder.append(", pages=");
        builder.append(pages);
        builder.append(", startRow=");
        builder.append(startRow);
        builder.append(", endRow=");
        builder.append(endRow);
        builder.append(", orders=");
        builder.append(orders);
        builder.append(", search=");
        builder.append(search);
        builder.append(", searchMap=");
        builder.append(searchMap);
        builder.append(", list=");
        builder.append(list);
        builder.append("]");
        return builder.toString();
    }
    
}
